<template>
  <div class="JNPF-common-layout">
    <div class="JNPF-common-layout-center">
      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent label-width="80px">
            <el-col :span="6">
                <el-form-item label="用户账号">
                    <el-input v-model="listQuery.id" clearable class="filter-item" placeholder="请输入用户账号" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="用户名称">
        <el-input v-model="listQuery.username" clearable class="filter-item" placeholder="请输入用户名称" />
      </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="使用场地">
        <el-select v-model="listQuery.fsiteNoBelong" :disabled="$store.state.user.froleid == 3" clearable filterable class="filter-item"
          placeholder="请选择使用场地">
          <el-option v-for="item in fsiteNoBelongOptions2" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item>
        <el-button  @click="handleFilter" type="primary" >查找</el-button>
        <el-button   @click="handleCreate" type="success">添加</el-button>
      </el-form-item>
            </el-col>
        </el-form>
      </el-row>
      <div class="JNPF-common-layout-main JNPF-flex-main">
       <!-- 查询结果 -->
    <JNPF-table  v-loading="listLoading" :data="list" @row-click="rowclick">
      <el-table-column align="center" :width="buttonColor.operationThree" width="150" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          
          <div v-if="adminFlag == 1" class="operationButton">
            <el-button type="text" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
            <el-dropdown trigger="click" @command="handleCommand">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">密码重置</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
          </div>

          <div v-else-if="adminFlag == 2" class="operationButton">
            <el-button type="text" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
            <el-dropdown trigger="click" @command="handleCommand">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">密码重置</el-dropdown-item>
                <el-dropdown-item command="b" v-show="formatSite2(scope.row.fsiteNoBelong) === 3">实验室授权</el-dropdown-item>
                <el-dropdown-item command="c" v-show="formatSite2(scope.row.fsiteNoBelong) === 3">管理柜授权</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div v-else class="operationButton">
            <el-button type="text" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
            <el-dropdown trigger="click" @command="handleCommand">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">密码重置</el-dropdown-item>
                <el-dropdown-item command="b"  v-if="scope.row.froleid == 2 || $store.state.user.id == scope.row.id">实验室授权</el-dropdown-item>
                <el-dropdown-item command="c" v-if="scope.row.froleid == 2 || $store.state.user.id == scope.row.id">管理柜授权</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.line" :index="indexMethod" align="center" label="序号" type="index" sortable />
      <el-table-column width="80" align="left" label="用户账号" prop="id" />
      <el-table-column width="130" align="left" label="用户名称" prop="username" />
      <el-table-column align="left" label="用户角色" prop="roleIds" width="130">
        <template slot-scope="scope">
          <el-tag  v-for="roleId in scope.row.roleIds" :key="roleId" > {{ formatRole(roleId) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="180" :formatter="formatSite" align="left" label="使用场地" prop="fsiteNoBelong" />
      <el-table-column width="112" align="left" label="手机" prop="phone" />
      <el-table-column width="210" align="left" label="邮箱" prop="email" />
      <el-table-column width="112" align="left" label="卡号" prop="fcard" />
      <el-table-column align="left" label="用户类型" prop="ftype">
        <template slot-scope="scope">
          <span :style="{ color: buttonColor.typeback }" v-if="scope.row.ftype === 1">{{ scope.row.ftype | userTypeFilter
          }}</span>
          <span :style="{ color: buttonColor.typefront }" v-else-if="scope.row.ftype === 2">{{ scope.row.ftype |
              userTypeFilter
          }}</span>
          <span :style="{ color: buttonColor.typeall }" v-else>{{ scope.row.ftype | userTypeFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column align="left" label="状态" prop="status">
        <template slot-scope="scope">
          <span :style="{ color: buttonColor.statedisable }" v-if="scope.row.status == 0">{{ scope.row.status | statusFilter
          }}</span>
          <span :style="{ color: buttonColor.statestart }" v-else>{{ scope.row.status | statusFilter }}</span>
        </template>
      </el-table-column>
    </JNPF-table>
    <paginations
	:total="total"
	:page.sync="listQuery.currentPage"
	:limit.sync="listQuery.pageSize"
	/>
      </div>
    </div>
    <!-- 添加或修改对话框 -->
    <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="80%">
     <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent ref="dataForm" :rules="rules" :model="dataForm" label-width="80px">
            <el-col :span="8">
                <el-form-item label="用户账号" prop="id">
                    <el-input :disabled="dialogStatus != 'create'" v-model="dataForm.id" type="number" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item class="el-form-item-small" label="状态" prop="status">
              <el-select v-model="dataForm.status" class="filter-item" placeholder="请选择状态">
                <el-option v-for="(key, value) in statusMap" :key="key" :label="key" :value="value" />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="8">
                 <el-form-item label="用户名称" prop="username">
              <el-input v-model="dataForm.username" />
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item  label="使用场地" prop="fsiteNoBelong">
              <el-select  :disabled="$store.state.user.froleid == 3" v-model="dataForm.fsiteNoBelong" filterable placeholder="请选择使用场地">
                <el-option v-for="item in fsiteNoBelongOptions2" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item   label="用户角色" prop="roleIds">
              <el-select disabled v-model="dataForm.roleIds" multiple placeholder="请选择">
                <el-option v-for="item in roleOptions" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item  label="用户类型" prop="ftype">
              <el-select v-model="dataForm.ftype" class="filter-item" placeholder="请选择用户类型">
                <el-option v-for="(key, value) in userTypeMap" :key="key" :label="key" :value="value" />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item  label="手机" prop="phone">
              <el-input v-model="dataForm.phone" />
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item  label="邮箱" prop="email">
              <el-input v-model="dataForm.email" />
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="卡号" prop="fcard">
              <el-input v-model="dataForm.fcard" />
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="平台编号" prop="nickName">
              <el-input v-model="dataForm.nickName" />
            </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item class="text" style="width: 100%" label="备注" prop="note">
              <el-input v-model="dataForm.note" />
            </el-form-item>
            </el-col>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button  @click="dialogFormVisible = false" type="info">取消</el-button>
        <el-button type="primary"  v-if="dialogStatus == 'create'" @click="createData">确定</el-button>
        <el-button type="primary" v-else   @click="updateData">确定</el-button>
      </span>
    </el-dialog>

    <!-- 导出弹窗 -->
    <el-dialog width="auto" :close-on-click-modal="false" :visible.sync="uploadVisible">
      <template slot="title">
        <div :style="exportColor">用户资料</div>
      </template>
      <div style="width:300px;height:200px;display: flex;flex-direction: column;align-items: center">
        <el-upload :on-success="uploadFileSuccess" :headers="headers" :action="uploadPath2"
          :data="{ 'tableName': 'import_i_ts_admin' }" :show-file-list="false" class="filter-item" style="margin-top:20px"
          accept=".xlsx">
          <el-button round size="medium" icon="el-icon-upload"
            :style="{ background: buttonColor.import, color: buttonColor.color }">导入</el-button>
        </el-upload>
        <div style="margin-top:30px;text-decoration:underline">
          <a :href="downUrl" style="color: blue">模板文件下载</a>
        </div>

      </div>
    </el-dialog>

    <!-- 权限配置对话框 :props="defaultProps"  -->
    <el-dialog width="400px" :close-on-click-modal="false" title="实验室权限" :visible.sync="permissionDialogFormVisible">
      <el-tree style="height:400px !important;overflow:auto !important;padding: 0 20px !important" ref="tree2"
        :data="systemPermissions" :default-checked-keys="assignedPermissions" show-checkbox node-key="id" />
      <div slot="footer" class="dialog-footer">
        <el-button  :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="permissionDialogFormVisible = false">取消</el-button>
        <el-button  :style="{ background: buttonColor.confirm, color: buttonColor.color }" @click="updatePermission">确定
        </el-button>
      </div>
    </el-dialog>

    <!-- 管理柜权限配置对话框 :props="defaultProps"  -->
    <el-dialog width="400px" :close-on-click-modal="false" title="管理柜权限" :visible.sync="permissionDialogFormVisibleGui">
      <el-tree style="height:400px !important;overflow:auto !important;padding: 0 20px !important" ref="tree3"
        :data="systemPermissionsGui" :default-checked-keys="assignedPermissionsGui" show-checkbox node-key="id" />
      <div slot="footer" class="dialog-footer">
        <el-button  :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="permissionDialogFormVisibleGui = false">取消</el-button>
        <el-button  :style="{ background: buttonColor.confirm, color: buttonColor.color }" @click="updatePermissionGui">
          确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style scoped>
.el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
</style>
<script>
import {
  listAdmin,
  createAdmin,
  updateAdmin,
  deleteAdmin,
  resetPassword,
  exportXsl,
} from "@/api/admin";
import { uploadPath2, fsiteOptionsByLevel2 } from "@/api/area";
import { getApiUrl } from "@/utils/request";
import { roleOptions, fsiteNoBelongOptions } from "@/api/role";
import { uploadPath } from "@/api/storage";
import { listArea } from "@/api/area";
import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination";
import {
  listPointByFsiteNo2,
  getPermissions,
  updatePermission,
  getPermissionsBox,
  updatePermissionBox,
} from "@/api/airAlarm";
import {
  tableColor,
  titleColor,
  buttonColor,
  exportColor,
} from "@/filters/index";

const userTypeMap = {
  1: "后端",
  2: "前端",
  3: "全部",
};
const statusMap = {
  0: "禁用",
  1: "启用",
};
export default {
  name: "Admin",
  components: { Pagination },
  filters: {
    userTypeFilter(type) {
      return userTypeMap[type];
    },
    statusFilter(type) {
      return statusMap[type];
    },
  },
  data() {
    return {
      adminFlag: null,
      downUrl: null,
      rowdata:{},
      exportColor,
      uploadPath2,
      uploadVisible: false,
      buttonColor,
      uploadPath,
      list: null,
      total: 0,
      roleOptions: null,
      roleOptionsSuperAdmin: null,
      fsiteNoBelongOptions: null,
      fsiteNoBelongOptions2: null,
      atsSites: null,
      atsPoints: null,
      permissionDialogFormVisible: false,
      systemPermissions: null,
      assignedPermissions: null,
      permissionForm: {
        userId: undefined,
        permIds: [],
      },
      permissionDialogFormVisibleGui: false,
      systemPermissionsGui: null,
      assignedPermissionsGui: null,
      permissionFormGui: {
        userId: undefined,
        permIds: [],
      },
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        id: undefined,
        username: undefined,
        roleIds: undefined,
        fsiteNoBelong: undefined,
        excludeAdmin: 3,
        ftype: undefined,
        sort: "create_time",
        order: "desc",
      },
      listQuery2: {
        fsiteLevel: 3,
      },
      userTypeMap,
      statusMap,
      dataForm: {
        id: undefined,
        username: undefined,
        fsiteNoBelong: undefined,
        phone: undefined,
        fcard: undefined,
        nickName: undefined,
        note: undefined,
        email: undefined,
        roleIds: [],
        fpointNoesVo: [],
        atsPoints: [],
      },
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        update: "编辑",
        create: "创建",
      },
      tableColor: tableColor,
      titleColor: titleColor,
      rules: {
        id: [{ required: true, message: "用户账号不能为空", trigger: "blur" }],
        username: [
          { required: true, message: "用户名称不能为空", trigger: "blur" },
        ],
        roleIds: [
          { required: true, message: "用户角色不能为空", trigger: "blur" },
        ],
        fsiteNoBelong: [
          { required: true, message: "使用场地不能为空", trigger: "blur" },
        ],
        ftype: [
          { required: true, message: "用户类型不能为空", trigger: "blur" },
        ],
        phone: [{ required: true, message: "手机不能为空", trigger: "blur" }],
        email: [{ required: true, message: "邮箱不能为空", trigger: "blur" }],
      },
      downloadLoading: false,
    };
  },
  computed: {
    headers() {
      return {
        Authorization: getToken(),
      };
    },
  },
  created() {
    // 超级管理员可以看到确认拒绝按钮
    // console.log("this.$store.state.user", this.$store.state.user);
    this.adminFlag = this.$store.state.user.roles[0];
    if (this.$store.state.user.froleid == 1) {
      this.roleOptionsSuperAdmin = [{ value: 2, label: "超级管理员" }];
    } else if (this.$store.state.user.froleid == 2) {
      this.roleOptionsSuperAdmin = [{ value: 3, label: "管理员" }];
    } else if (this.$store.state.user.froleid == 3) {
      this.roleOptionsSuperAdmin = [{ value: 4, label: "实验人员" }];
    }
    if (this.$store.state.user.froleid == 3) {
      this.listQuery.fsiteNoBelong = this.$store.state.user.fsiteNo;
    }
    this.downUrl = getApiUrl() + "xlsx/1-7用户资料.xlsx";
    this.getList();
    roleOptions()
      .then((response) => {
        this.roleOptions = response.data.data.list;
      })
      .catch(() => {
        this.roleOptions = [];
      });
    fsiteOptionsByLevel2(3)
      .then((response) => {
        this.fsiteNoBelongOptions2 = response.data.data.list;
      })
      .catch(() => {
        this.fsiteNoBelongOptions2 = [];
      });
    fsiteNoBelongOptions()
      .then((response) => {
        this.fsiteNoBelongOptions = response.data.data.list;
      })
      .catch(() => {
        this.fsiteNoBelongOptions = [];
      });
    listArea(this.listQuery2)
      .then((response) => {
        this.atsSites = response.data.data.list;
      })
      .catch(() => {
        this.atsSites = [];
      });
  },
  methods: {
    // 导入
    uploadFileSuccess: function (response) {
      this.uploadVisible = false;
      this.$notify.success({
        title: "导入",
        dangerouslyUseHTMLString: true,
        message: response.data,
      });
    },
    handleUpload() {
      this.uploadVisible = true;
    },

    listPoint(fsiteNo) {
      listPointByFsiteNo2(fsiteNo)
        .then((response) => {
          this.atsPoints = response.data.data.list;
        })
        .catch(() => {
          this.atsPoints = [];
        });
    },
    formatRole(roleId) {
      if (this.roleOptions) {
        for (let i = 0; i < this.roleOptions.length; i++) {
          if (roleId === this.roleOptions[i].value) {
            return this.roleOptions[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    formatRoleName(roleName) {
      if (this.roleOptions) {
        for (let i = 0; i < this.roleOptions.length; i++) {
          if (roleName === this.roleOptions[i].label) {
            return this.roleOptions[i].value;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    formatSite2(fsiteNo) {
      console.log("this.fsiteNo", fsiteNo);
      console.log("this.atsSites", this.atsSites);
      if (this.atsSites) {
        for (let i = 0; i < this.atsSites.length; i++) {
          if (fsiteNo === this.atsSites[i].fsiteNo) {
            return this.atsSites[i].fsiteLevel;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    formatStatus: function (row, column) {
      return row.status === 1 ? "启用" : "禁用";
    },
    formatSite: function (row, column) {
      if (this.fsiteNoBelongOptions) {
        for (let i = 0; i < this.fsiteNoBelongOptions.length; i++) {
          if (row.fsiteNoBelong === this.fsiteNoBelongOptions[i].value) {
            return this.fsiteNoBelongOptions[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    getList() {
      this.listLoading = true;
      listAdmin(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list;
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false;
        });
    },
    //点击更多
    handleCommand(e){
      if(e=="a")
      {
        this.handleResetPassword(this.rowdata);
      }
       if(e=="b")
      {
        this.handlePermission(this.rowdata);
      }
       if(e=="a")
      {
        this.handlePermissionGui(this.rowdata);
      }
    },
    rowclick(e){
     this.rowdata=e;
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    resetForm() {
      this.dataForm = {
        id: undefined,
        username: undefined,
        fsiteNoBelong: undefined,
        phone: undefined,
        fcard: undefined,
        nickName: undefined,
        note: undefined,
        email: undefined,
        roleIds: [],
        fpointNoesVo: [],
        atsPoints: [],
      };
    },
    handleCreate() {
      this.resetForm();
      this.dialogStatus = "create";
      this.dataForm.status = "1";
      this.dataForm.roleIds = [this.roleOptionsSuperAdmin[0].value];
      if (this.$store.state.user.froleid == 3) {
        this.dataForm.fsiteNoBelong = this.fsiteNoBelongOptions2[0].value;
      }
      this.dataForm.ftype = "3";
      this.dialogFormVisible = true;
      this.atsPoints = null;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    createData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          var phoneReg = /^1[3-9][0-9]{9}$/;
          if (!phoneReg.test(this.dataForm.phone)) {
            this.$notify.error({
              title: "失败",
              message: "手机号格式不正确",
            });
            return;
          }
          var emailreg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
          if (!emailreg.test(this.dataForm.email)) {
            this.$notify.error({
              title: "失败",
              message: "邮箱格式不正确",
            });
            return;
          }
          createAdmin(this.dataForm)
            .then((response) => {
              this.list.unshift(response.data.data);
              this.dialogFormVisible = false;
              this.$notify.success({
                title: "成功",
                message: "添加用户成功",
              });
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.data,
              });
            });
        }
      });
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row);
      this.dataForm.ftype = row.ftype.toString();
      this.dataForm.status = row.status.toString();
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleResetPassword(row) {
      this.$confirm("是否要重置" + row.username + "用户密码", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        resetPassword(row)
          .then((response) => {
            this.$notify.success({
              title: "成功",
              message:
                "重置" +
                row.username +
                "用户密码成功，初始密码[" +
                response.data.data +
                "]",
            });
          })
          .catch((response) => {
            this.$notify.error({
              title: "失败",
              message: response.data.msg,
            });
          });
      });
    },
    updateData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          var phoneReg = /^1[3-9][0-9]{9}$/;
          if (!phoneReg.test(this.dataForm.phone)) {
            this.$notify.error({
              title: "失败",
              message: "手机号格式不正确",
            });
            return;
          }
          var emailreg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
          if (!emailreg.test(this.dataForm.email)) {
            this.$notify.error({
              title: "失败",
              message: "邮箱格式不正确",
            });
            return;
          }
          updateAdmin(this.dataForm)
            .then(() => {
              for (const v of this.list) {
                if (v.id === this.dataForm.id) {
                  const index = this.list.indexOf(v);
                  this.dataForm.status = parseInt(this.dataForm.status);
                  this.list.splice(index, 1, this.dataForm);
                  break;
                }
              }
              this.dialogFormVisible = false;
              this.$notify.success({
                title: "成功",
                message: "更新用户成功",
              });
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.data,
              });
            });
        }
      });
    },
    handleDelete(row) {
      this.$confirm("是否要删除该用户", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteAdmin(row)
          .then((response) => {
            this.$notify.success({
              title: "成功",
              message: "删除用户成功",
            });
            const index = this.list.indexOf(row);
            this.list.splice(index, 1);
          })
          .catch((response) => {
            this.$notify.error({
              title: "失败",
              message: response.data.msg,
            });
          });
      });
    },
    handleExport(row) {
      this.$confirm("是否要导出数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        exportXsl(this.dataForm)
          .then((response) => {
            this.$notify.success({
              title: "成功",
              message: "导出成功",
            });
          })
          .catch((response) => {
            this.$notify.error({
              title: "失败",
              message: response.data.msg,
            });
          });
      });
    },
    handlePermission(row) {
      this.permissionDialogFormVisible = true;
      this.permissionForm.userId = row.id;
      getPermissions(row.id, row.fsiteNoBelong)
        .then((response) => {
          this.systemPermissions = response.data.data.all;
          this.assignedPermissions = response.data.data.assigned;
        })
        .catch(() => {
          this.systemPermissions = [];
          this.assignedPermissions = [];
        });
      /* this.systemPermissions = [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        children: [{
          id: 5,
          label: '二级 2-1'
        }, {
          id: 6,
          label: '二级 2-2'
        }]
      }, {
        id: 3,
        label: '一级 3',
        children: [{
          id: 7,
          label: '二级 3-1'
        }, {
          id: 8,
          label: '二级 3-2'
        }]
      }]*/
    },
    updatePermission() {
      this.permissionForm.permIds = this.$refs.tree2.getCheckedKeys(false);
      updatePermission(this.permissionForm)
        .then((response) => {
          this.permissionDialogFormVisible = false;
          this.$notify.success({
            title: "成功",
            message: "授权成功",
          });
        })
        .catch((response) => {
          this.$notify.error({
            title: "失败",
            message: response.data.msg,
          });
        });
    },
    handlePermissionGui(row) {
      this.permissionDialogFormVisibleGui = true;
      this.permissionFormGui.userId = row.id;
      console.log("row", row);
      getPermissionsBox(row.id, row.fsiteNoBelong)
        .then((response) => {
          this.systemPermissionsGui = response.data.data.all;
          this.assignedPermissionsGui = response.data.data.assigned;
        })
        .catch(() => {
          this.systemPermissionsGui = [];
          this.assignedPermissionsGui = [];
        });
    },
    updatePermissionGui() {
      this.permissionFormGui.permIds = this.$refs.tree3.getCheckedKeys(false);
      console.log(
        "this.permissionFormGui.permIds",
        this.permissionFormGui.permIds
      );
      updatePermissionBox(this.permissionFormGui)
        .then((response) => {
          this.permissionDialogFormVisibleGui = false;
          this.$notify.success({
            title: "成功",
            message: "授权成功",
          });
        })
        .catch((response) => {
          this.$notify.error({
            title: "失败",
            message: response.data.msg,
          });
        });
    },
    indexMethod(index) {
      index = index + 1;
      return index;
    },
  },
};
</script>